cmake_minimum_required(VERSION 3.12)
project(klippy_cpp LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 编译器警告
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    add_compile_options(-Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter)
endif()
# 项目配置
set(SOURCE_DIR src)
set(INCLUDE_DIR include include/klippy)
set(TEST_DIR tests)

# 源文件列表
file(GLOB_RECURSE SOURCES 
    ${SOURCE_DIR}/*.cpp 
    ${SOURCE_DIR}/*.h
)

# 库配置
add_library(klippy_cpp STATIC
    ${SOURCES}
)

# 依赖库
find_package(Threads REQUIRED)

# 包含目录
target_include_directories(klippy_cpp PRIVATE ${INCLUDE_DIR})

# 链接库
target_link_libraries(klippy_cpp PRIVATE Threads::Threads)

# 添加主程序可执行文件
add_executable(klippy ${SOURCE_DIR}/main.cpp)
target_include_directories(klippy PRIVATE ${INCLUDE_DIR})
target_link_libraries(klippy PRIVATE klippy_cpp Threads::Threads)

# 安装配置
install(TARGETS klippy_cpp DESTINATION bin)
install(DIRECTORY ${INCLUDE_DIR}/klippy DESTINATION include)

# 测试配置
find_package(GTest REQUIRED)
enable_testing()

# 添加测试可执行文件
add_executable(core_test ${TEST_DIR}/core_test.cpp)
target_include_directories(core_test PRIVATE ${INCLUDE_DIR})
target_link_libraries(core_test PRIVATE GTest::GTest GTest::Main klippy_cpp)

add_executable(reactor_test ${TEST_DIR}/reactor_test.cpp)
target_include_directories(reactor_test PRIVATE ${INCLUDE_DIR})
target_link_libraries(reactor_test PRIVATE GTest::GTest GTest::Main klippy_cpp)

# 添加测试
add_test(NAME core_test COMMAND core_test)
add_test(NAME reactor_test COMMAND reactor_test)

# 代码覆盖率
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
    include(CodeCoverage)
    setup_target_for_coverage(klippy_cpp_coverage klippy_cpp)
endif()